package com.LC.Service;

import com.LC.DAO.UserDAO;
import com.LC.Entity.LoginUser;
import com.LC.Entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailServiceImpl implements UserDetailsService {

    @Autowired
    UserDAO userDAO;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        //查询用户信息
        User byUserName = userDAO.findByUserName(username);
        if (byUserName == null){
            throw new RuntimeException("用户名或密码错误！");
        }

        //TODO:查询对应的权限信息


        //把用户封装成 UserDetails 返回
        return new LoginUser(byUserName);
    }
}
